package com.absir.android;

import android.app.Activity;
import android.app.Application;
import android.content.Context;
import android.database.Cursor;
import android.graphics.drawable.Drawable;
import android.widget.Button;

import com.absir.android.inject.annotation.InjectResouce;
import com.absir.android.orm.DaoCursorUtils;
import com.absir.android.orm.DaoFactory;
import com.absir.android.pojo.JUserTable;
import com.absir.android.view.annotation.InjectBinder;
import com.absir.android.view.annotation.InjectLayer;
import com.absir.android.view.annotation.InjectListener;
import com.absir.android.view.annotation.InjectMethod;
import com.absir.android.view.annotation.InjectView;
import com.absir.android.view.listener.OnClick;
import com.absir.bean.inject.value.Inject;
import com.j256.ormlite.dao.Dao;

@InjectLayer(R.layout.activity_main)
public class MainActivity extends Activity {

	@Inject
	Application application;

	@InjectView(value = R.id.button1, binders = @InjectBinder(listeners = OnClick.class, method = "click"))
	Button button;

	@InjectView
	Button button2;

	@InjectView(R.id.button3)
	Button button3;

	@InjectResouce(R.string.app_name)
	String appName;

	@InjectResouce(R.drawable.ic_launcher)
	Drawable icDrawable;

	@Inject
	DaoFactory daoFactory;

	@InjectMethod(@InjectListener(value = R.id.button2, listeners = { OnClick.class }))
	public void click(Button button) {

	}

	@Inject
	public void inject(Context context) {
		// System.out.println("Context = " + context);
		// System.out.println("Application = " + application);
		System.out.println("MainActivity Inject began!");
		try {
			Dao<JUserTable, Long> dao = daoFactory.getDaoHelper().getDao(JUserTable.class);

			JUserTable userTable = new JUserTable();
			userTable.setUsername("123");
			dao.create(userTable);
			System.out.println(dao);

			Cursor cursor = daoFactory.getDaoHelper().getReadableDatabase().rawQuery("SELECT * from jusertable", null);
			DaoCursorUtils.getOneRow(cursor);

			// TableUtils.

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
